package com.hqs.listener.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.hqs.listener.R;

/**
 * Created by super on 2017/11/11.
 */

public class RoundTextView extends android.support.v7.widget.AppCompatTextView{


    public boolean selected = false;
    public int value;
    private OnSelectedStateChangedListener onSelectedStateChangedListener;

    public RoundTextView(Context context) {
        super(context);
        setup();
    }

    public RoundTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        setup();
    }


    void setup(){
        this.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                selected = !selected;
                updateUI();
                if (onSelectedStateChangedListener != null){
                    onSelectedStateChangedListener.onSelectedStateChanged(selected, value);
                }
            }
        });
    }

    void updateUI(){
        if (selected){
            this.setBackgroundResource(R.drawable.time_bg_s);
        }
        else {
            this.setBackgroundResource(R.drawable.time_bg);
        }
    }

    public void setSelected(boolean s){
        this.selected = s;
        updateUI();
    }

    public void setOnSelectedStateChangedListener(OnSelectedStateChangedListener onSelectedStateChangedListener) {
        this.onSelectedStateChangedListener = onSelectedStateChangedListener;
    }

    public interface OnSelectedStateChangedListener {
        void onSelectedStateChanged(boolean selected, int value);
    }

}



